package com.engr.business.util;

import org.apache.http.client.fluent.Request;
import org.apache.http.entity.StringEntity;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @program: business
 * @desc: http工具类
 * @author: lyx
 * @date: 2019-01-04 12:03
 **/
public class HttpClientUtils {

    /**
     * @param url
     * @param jsonStr
     * @return
     */
    public static byte[] httpPost(String url, String jsonStr) {
        try {
            return Request.Post(url)
                    .addHeader("Accept", "application/json")
                    .addHeader("Content-type", "application/json")
                    .body(new StringEntity(jsonStr, StandardCharsets.UTF_8)).
                            execute().returnContent().asBytes();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
